package cn.aliang.cloud.hystrixorder.controller;

import cn.aliang.cloud.hystrixorder.service.PaymentHystrixService;
import cn.aliang.cloud.service.entity.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chendongliang
 * @Date: 2020/7/21 10:16
 *
 *
 * 调用支付端熔断接口
 *
 */

@RestController
@RequestMapping("/order/hystrix")
public class OrderHystrixPaymentController {


    @Autowired
    PaymentHystrixService paymentHystrixService ;

    /*****
     * 一个接口对应一个降级回调方法
     * 需要降级的接口很多时，会导致回调接口增多，代码量爆炸
     */

    @GetMapping("/pay/{id}")
    public ResultMessage<Void> pay(@PathVariable("id") String id ) {

        return paymentHystrixService.pay(id);
    }


    /****
     *  采用全局降级回调方法
     */
    @GetMapping("/payCircuitBreaker/{id}")
    public ResultMessage<Void> payCircuitBreaker(@PathVariable("id") String id ){
        return paymentHystrixService.payCircuitBreaker(id);
    }




}
